my ($hostdir, $version) = @ARGV;
my ($vMajor,$vMinor,$vRelease,$vBuild) = split('\.', $version);
print $vMajor.$vMinor.$vRelease.$vBuild;

my $versionFile = $hostdir."/include/Version.h";
my $packageFile = $hostdir."/package.xml";
my $changelogFile = $hostdir."/debian/changelog";

open (FILE, $versionFile) or die "couldn't open $versionFile - $!";
my @lines = <FILE>;
close FILE;

open (FILE, ">$versionFile") or die "couldn't open $versionFile for writing - $!"; 
foreach my $line (@lines)
{
   $line =~ s/(\#define INUROS_VERSION_1[^\d]+)\d+(.*)/$1$vMajor$2/;
   $line =~ s/(\#define INUROS_VERSION_2[^\d]+)\d+(.*)/$1$vMinor$2/;
   $line =~ s/(\#define INUROS_VERSION_3[^\d]+)\d+(.*)/$1$vRelease$2/;
   $line =~ s/(\#define INUROS_VERSION_4[^\d]+)\d+(.*)/$1$vBuild$2/;
   $line =~ s/\#define INUROS_VERSION_STR.+/#define INUROS_VERSION_STR "$vMajor.$vMinor.$vRelease.$vBuild"/;
   printf FILE $line;
}
close FILE;

open (FILE, $packageFile) or die "couldn't open $packageFile - $!";
my @lines = <FILE>;
close FILE;

open (FILE, ">$packageFile") or die "couldn't open $packageFile - $!";
foreach my $line (@lines)
{
   $line =~ s/<version>\s*(.*)/<version>$vMajor.$vMinor.$vRelease<\/version>/;
   printf FILE $line;
}
close FILE;


open (FILE, $changelogFile) or die "couldn't open $changelogFile - $!";
my @lines = <FILE>;
close FILE;

open (FILE, ">$changelogFile") or die "couldn't open $changelogFile - $!";
foreach my $line (@lines)
{
   $line =~ s/ros-noetic-inudev-ros-nodelet \(\s*(.*)/ros-noetic-inudev-ros-nodelet \($vMajor.$vMinor.$vRelease-0bionic) bionic; urgency=high/;	
   printf FILE $line;
}
close FILE;
